package com.company;


public class Ant {
    private int id;
    private int velocity;
    private int direction; //0=left,1=right
    private int position;
    private int leftTime; //离开时间
    private int inRange; //0=not in,1=in

    public Ant(){
        setVelocity(5);
        setInRange(1);
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getVelocity() {
        return velocity;
    }

    public void setVelocity(int velocity) {
        this.velocity = velocity;
    }

    public int getDirection() {
        return direction;
    }

    public void setDirection(int direction) {
        this.direction = direction;
    }

    public int getPosition() {
        return position;
    }

    public void setPosition(int position) {
        this.position = position;
    }

    public int getLeftTime() {
        return leftTime;
    }

    public void setLeftTime(int leftTime) {
        this.leftTime = leftTime;
    }

    public int getInRange() {
        return inRange;
    }

    public void setInRange(int inRange) {
        this.inRange = inRange;
    }

    public void changDirection() {
        direction = 1 - direction;
    }

    public void creepingOneStep() {
        if (inRange == 0) return;
        if (direction == 0) {
            position -= velocity * PlayRoom.incTime;
        } else if (direction == 1) {
            position += velocity * PlayRoom.incTime;
        }
    }

    public void collision() {
        changDirection();
    }

    public void judgeRange() {
        if (position <= Pole.left || position >= Pole.right) {
            setInRange(0);
        } else setInRange(1);
    }
}
